home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10122 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  67 lines

  1. Path: inforamp.net!ts26-11
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: borland c 4.5
  5. Date: Wed, 06 Mar 96 06:03:23 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4hj9r3$elu@sam.inforamp.net>
  8. References: <4h9uai$ecj@rzsun02.rrz.uni-hamburg.de>
  9. NNTP-Posting-Host: ts26-11.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4h9uai$ecj@rzsun02.rrz.uni-hamburg.de>,
  13.    mleusch@rzdspc1.informatik.uni-hamburg.de (Michael Leuschner) wrote:
  14. >It seems that the c++ compiler is able to compile our
  15. >ANSI c sources but later the linker can't manage to link the mix of
  16. >c++ and c together...
  17. >
  18. >Does anyone have a clue?
  19. >Is the a known problem (and how can you solve it) ?
  20.  
  21. I would be more certain if you could tell me what errors were occuring, but it 
  22. might be a name-mangling problem.  If you know its not a 
  23. name-mangling problem then ignore this post.  But generally, when declaring a 
  24. C extern function in a C++ source, you specify...
  25.  
  26.     extern "C" void f();
  27.  
  28. alternative you could specify the following syntax...
  29.  
  30.     #ifdef __cplusplus
  31.     extern "C" 
  32.     #endif
  33.     void f();
  34.  
  35. you could also do the following...
  36.  
  37.     #ifdef __cplusplus
  38.     extern "C" {
  39.     #endif
  40.     
  41.     #include <cfile.h>
  42.     
  43.     #ifdef __cplusplus
  44.     }
  45.     #endif
  46.  
  47. or you could even embed the __cplusplus demangling statements inside your 
  48. header...
  49.  
  50. #ifndef HELLO_H
  51. #define HELLO_H
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif /* __cplusplus */
  55.     
  56. ..
  57.     
  58. #ifdef __cplusplus
  59. }
  60. #endif /* __cplusplus */
  61. #endif /* HELLO_H */
  62.  
  63. The solution you choose depends on your preferences, but I tend to use a 
  64. mixture of all four methods.
  65.  
  66. Agrivar
  67.